#include <vector>//不能省略
#include <iostream>
using std::cout;
using std::endl;
using std::vector;
using std::string;

void test0(){
    int arr[5] = {1,2,3,4,5};

    //<>中写要存放的元素的类型
    vector<int> numbers;
    vector<long> numbers2;
    cout << "numbers's size:" << numbers.size() << endl;

    //这里的参数代表vector的容量，每个元素会初始化为默认值
    vector<int> numbers3(10);
    cout << "numbers3's size:" << numbers3.size() << endl;

    for(size_t idx = 0; idx < numbers3.size(); ++idx){
        cout << numbers3[idx] << " ";
    }
    cout << endl;

#if 0
    //如果vector存的元素是char*,注意避免输出空指针
    vector<char*> numbers4(10);
    cout << "numbers4's size:" << numbers4.size() << endl;

    cout << "hello";
    for(size_t idx = 0; idx < numbers4.size(); ++idx){
        cout << numbers4[idx] << endl;
    }
    cout << endl;
#endif

    //采用迭代器的方式创建vector
    //arr代表数组的arr的首个元素的地址，
    //arr+5代表数组arr的最后一个元素的后一位地址
    //参数是地址，左闭右开
    vector<int> numbers5(arr,arr + 5);
    for(auto & x : numbers5){
        cout << x << " ";
    }
    cout << endl;

    string str("hello");
    vector<char> strArr(str.begin(),str.end());
    for(auto & ch : strArr){
        cout << ch << " ";
    }
    cout << endl;

    //存放容器的vector的构造
    vector<string> numbers6(2,str);
    for(auto & st : numbers6){
        cout << st << " ";
    }
    cout << endl;

    vector<int> numbers7(10);
    vector<vector<int>> numbers8(2,numbers7);
    for(auto & ve : numbers8){
        for(auto & x : ve){
            cout << x << " ";
        }
        cout << endl;
    }
    cout << endl;

    //也可以用大括号直接创建vector，类似于数组
    vector<int> numbers9{1,2,3,4,5};
    for(auto & num : numbers9){
        cout << num << " ";
    }
    cout << endl;



}

int main(void){
    test0();
    return 0;
}
